package dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import dto.ChestionareDTO;
import dto.EmployeeDTO;
import dto.IntrebariDTO;
import dto.RaspunsuriCompletateDTO;
import dto.RaspunsuriDTO;
import entities.Chestionare;
import entities.Employee;
import entities.Intrebari;
import entities.Raspunsuri;
import entities.RaspunsuriCompletate;

public class Conversion implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public RaspunsuriDTO convertRaspunsToDTO(Raspunsuri r){
		RaspunsuriDTO rDTO = new RaspunsuriDTO();
		rDTO.setId(r.getId());
		rDTO.setRaspuns(r.getRaspuns());
		return rDTO;
	}
	
	public IntrebariDTO convertIntrebareToDTO(Intrebari i){
		IntrebariDTO iDTO = new IntrebariDTO();
		iDTO.setId(i.getId());
		iDTO.setIntrebare(i.getIntrebare());
		iDTO.setTip(i.getTip());
		List<RaspunsuriDTO> raspunsuri = new ArrayList<RaspunsuriDTO>();
		for (int j = 0; j < i.getRaspunsuri().size(); j++){
			RaspunsuriDTO r = new RaspunsuriDTO();
			r.setId(i.getRaspunsuri().get(j).getId());
			r.setRaspuns(i.getRaspunsuri().get(j).getRaspuns());
			raspunsuri.add(r);
		}
		iDTO.setRaspunsuri(raspunsuri);
		return iDTO;
	}
	
	public ChestionareDTO convertChestionareToDTO(Chestionare c){
		ChestionareDTO cDTO = new ChestionareDTO();
		cDTO.setId(c.getId());
		cDTO.setNume(c.getNume());
		cDTO.setScop(c.getScop());
		cDTO.setCategorie(c.getCategorie());
		cDTO.setSubcategorie(c.getSubcategorie());
		cDTO.setActiv(c.getActiv());
		List<IntrebariDTO> intrebari = new ArrayList<IntrebariDTO>();
		for (int j = 0; j < c.getIntrebari().size(); j++){
			IntrebariDTO i = new IntrebariDTO();
			i.setId(c.getIntrebari().get(j).getId());
			i.setIntrebare(c.getIntrebari().get(j).getIntrebare());
			i.setTip(c.getIntrebari().get(j).getTip());
			List<RaspunsuriDTO> raspunsuri = new ArrayList<RaspunsuriDTO>();
			for (int k = 0; k < c.getIntrebari().get(j).getRaspunsuri().size(); k++){
				RaspunsuriDTO r = new RaspunsuriDTO();
				r.setId(c.getIntrebari().get(j).getRaspunsuri().get(k).getId());
				r.setRaspuns(c.getIntrebari().get(j).getRaspunsuri().get(k).getRaspuns());
				raspunsuri.add(r);
			}
			i.setRaspunsuri(raspunsuri);
			intrebari.add(i);
		}
		cDTO.setIntrebari(intrebari);
		return cDTO;
	}
	
	public Raspunsuri convertRaspunsDTO(RaspunsuriDTO rDTO){
		Raspunsuri r = new Raspunsuri();
		r.setId(rDTO.getId());
		r.setRaspuns(rDTO.getRaspuns());
		return r;
	}
	
	public Intrebari convertIntrebareDTO(IntrebariDTO iDTO){
		Intrebari i = new Intrebari();
		i.setId(iDTO.getId());
		i.setIntrebare(iDTO.getIntrebare());
		i.setTip(iDTO.getTip());
		List<Raspunsuri> raspunsuri = new ArrayList<Raspunsuri>();
		for (int j = 0; j < iDTO.getRaspunsuri().size(); j++){
			Raspunsuri r = new Raspunsuri();
			r.setId(iDTO.getRaspunsuri().get(j).getId());
			r.setRaspuns(iDTO.getRaspunsuri().get(j).getRaspuns());
			raspunsuri.add(r);
		}
		i.setRaspunsuri(raspunsuri);
		return i;
	}
	
	public Chestionare convertChestionareDTO(ChestionareDTO cDTO){
		Chestionare c = new Chestionare();
		c.setId(cDTO.getId());
		c.setNume(cDTO.getNume());
		c.setScop(cDTO.getScop());
		c.setCategorie(cDTO.getCategorie());
		c.setSubcategorie(cDTO.getSubcategorie());
		c.setActiv(cDTO.getActiv());
		List<Intrebari> intrebari = new ArrayList<Intrebari>();
		for (int j = 0; j < cDTO.getIntrebari().size(); j++){
			Intrebari i = new Intrebari();
			i.setId(cDTO.getIntrebari().get(j).getId());
			i.setIntrebare(cDTO.getIntrebari().get(j).getIntrebare());
			i.setTip(cDTO.getIntrebari().get(j).getTip());
			List<Raspunsuri> raspunsuri = new ArrayList<Raspunsuri>();
			for (int k = 0; k < cDTO.getIntrebari().get(j).getRaspunsuri().size(); k++){
				Raspunsuri r = new Raspunsuri();
				r.setId(cDTO.getIntrebari().get(j).getRaspunsuri().get(k).getId());
				r.setRaspuns(cDTO.getIntrebari().get(j).getRaspunsuri().get(k).getRaspuns());
				raspunsuri.add(r);
			}
			i.setRaspunsuri(raspunsuri);
			intrebari.add(i);
		}
		
		c.setIntrebari(intrebari);
		return c;
	}
	
	public EmployeeDTO convertEmployeeToDTO(Employee employee){
		EmployeeDTO e = new EmployeeDTO();
		try{
		e.setFirstname(employee.getFirstname());	// baj van ebben a sorban :|
		e.setLastname(employee.getLastname());
		e.setAreaManager(employee.getAreaManager());
		e.setContactpersonde(employee.getContactpersonde());
		e.setDateofbirth(employee.getDateofbirth());
		e.setDepartment(employee.getDepartment());
		e.setDeparture_date(employee.getDeparture_date());
		e.setEmail(employee.getEmail());
		e.setEmpl_type(employee.getEmpl_type());
		e.setEmployment_date(employee.getEmployment_date());
		e.setLastmedicalvisit(employee.getLastmedicalvisit());
		e.setNet_salary(employee.getNet_salary());
		e.setPassword(employee.getPassword());
		e.setPosition(employee.getPosition());
		e.setProfile(employee.getProfile());
		e.setProsisnr(employee.getProsisnr());
		e.setRank(employee.getRank());
		e.setTeamleaderro(employee.getTeamleaderro());
		e.setUsername(employee.getUsername());
		e.setVar_part(employee.getVar_part());
		e.setId(employee.getId());
		e.setSelected_language(employee.getSelected_language());
		}
		catch (NullPointerException ex){
			ex.printStackTrace();
		}
		return e;
	}

	public RaspunsuriCompletate convertRaspunsuriCompletateDTO(
			RaspunsuriCompletateDTO rcDTO) {
		RaspunsuriCompletate rc = new RaspunsuriCompletate();
		rc.setId(rcDTO.getId());
		rc.setChestionarId(rcDTO.getChestionarId());
		rc.setIntrebareId(rcDTO.getIntrebareId());
		rc.setRaspuns(rcDTO.getRaspuns());
		rc.setAngajatId(rcDTO.getAngajatId());
		rc.setAngajatName(rcDTO.getAngajatName());
		// TODO Auto-generated method stub
		return rc;
	}
	
	public RaspunsuriCompletateDTO convertRaspunsuriCompletateToDTO(
			RaspunsuriCompletate rc){
		RaspunsuriCompletateDTO rcDTO = new RaspunsuriCompletateDTO();
		rcDTO.setId(rc.getId());
		rcDTO.setChestionarId(rc.getChestionarId());
		rcDTO.setIntrebareId(rc.getIntrebareId());
		rcDTO.setRaspuns(rc.getRaspuns());
		rcDTO.setAngajatId(rc.getAngajatId());
		rcDTO.setAngajatName(rc.getAngajatName());
		return rcDTO;
	}

}
